"use strict";
// pages/room/detail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: {},
    classinfo:{},
    approvetext:"",
    alladmin:'',
    classrelaid:0,
    month:0
  }, 
  bindKeyInput(e) {
    this.data[e.currentTarget.dataset.obj] = e.detail.value
  },
  refresh: function () {
    app.api.api_user_info().then(res => {
      this.setData({ info: res })
      app.globalData.userInfo = res
    })
    app.api.api_meeting_config().then(res => {
      app.globalData.config = res
    })
    // 获取本地的cookie
    var localCookie = wx.getStorageSync('cti_cookie');
    var alladminval = localCookie.alladmin.value//读取cookie
    this.setData({ alladmin: alladminval })
    this.refreshclass()
  },
  refreshclass:function(){
    app.api.api_user_classinfo({ classrelaid: this.data.classrelaid, month: this.data.month }).then(res => {
      this.setData({ classinfo: {} })
      this.setData({ classinfo: res })
    })
  },
  
  onGetUserInfo: function (e) {
    console.log("welcome.js:onGetUesrInfo");
    var that = this;
    app.getUserInfo(function(res){
      console.log("welcome.js:onGetUserInfo:SUCCESS------------");
      console.log(res);
      that.refresh();
    })
  },
  toy: function () {
    wx.navigateTo({
      url: '/pages/toy/toyget',
    })
  },
  intoclass:function(){
    wx.navigateTo({
      url: '/pages/user/intoclass',
    })
  },
  toymanager: function () {
    wx.navigateTo({
      url: '/pages/toy/toymanager',
    })
  },
  about: function () {
    wx.navigateTo({
      url: '/+paper/pages/questionnaire/questionnaire',
    })
  },
  papercount:function(){
    wx.navigateTo({
      url: '/+paper/pages/mypaper/mypaper',
    })
  },
  input_change: function (e) {
    app.api.api_user_find(e.detail).then(res => {
      this.selectComponent("#searchbar").setSelectVals(res);
    })
  },
  selected: function (e) {
    this.setData({ classrelaid: e.detail.id })
    this.refreshclass()
  },

  submit: function(){
    app.api.api_user_approve({approvetext:this.data.approvetext}).then(res => {
      wx.showToast({
        title: '已提交',
        icon: 'none'
      })
    })
  },
  permonth: function () {
    let wval = parseInt(this.data.month) - 1;
    this.setData({ month: wval })
    this.refreshclass()
  },
  nextmonth: function () {
    let wval = parseInt(this.data.month) + 1;
    this.setData({ month: wval })
    this.refreshclass()
  },
  roomslist: function(){
    wx.navigateTo({
      url: '../room/list'
    })
  }, 
  goadvise: function(){
    wx.navigateTo({
      url: '../user/adviseshow'
    })
  },
  gocount: function () {
    wx.navigateTo({
      url: '../meeting/list'
    })
  }, 
  meetingupload:function(){
    wx.navigateTo({
      url: '../meeting/upload'
    })
  },
  mymeetings: function(){
    wx.navigateTo({
      url: '../meeting/my'
    })
  },
  userlist:function(){
    wx.navigateTo({
      url: '../user/list'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.refresh()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.refresh()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let title = '筱薇课'
    if (this.data.info.name) {
      title += " - " + this.data.info.name
    }
    return {
      title: title,
      page: '/pages/user/welcome'
    }
  }
})